home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / turb2or3.arc / TURB2OR3.INC
Encoding:
Text File  |  1985-12-09  |  4.2 KB  |  128 lines

  1. FUNCTION which_turbo: INTEGER;
  2.  
  3.     {The upper left hand corner of the window is stored with the upper left
  4.      hand corner of the screen as (0,0) in:
  5.           Turbo, IBM-PC Version 2.00B - Dseg:$156, Dseg:$157
  6.           Turbo-87, IBM-PC Version 2.00B - Dseg:$143, Dseg:$144
  7.           Turbo, IBM-PC Version 3.01A - Dseg:$4, Dseg:$5
  8.           Turbo-87, IBM-PC Version 3.01A - Dseg:$4, Dseg:$5
  9.           Turbobcd, IBM-PC Version 3.01A - Dseg:$4, Dseg:$5
  10.  
  11.      The lower right hand corner of the window is stored with the upper left
  12.      hand corner of the screen as (1,10) in
  13.           Cseg:$16A, Cseg:$16B
  14.      in all three cases.
  15.  
  16.      The function tests which Turbo is being used by setting a window with a
  17.      different upper left hand corner, then seeing which one matches.  It
  18.      returns 3 for any IBM-PC Version 3.01A, 2 for Turbo, IBM-PC Version 
  19.      2.00B , 287 for Turbo-87, IBM-PC Version 2.00B, and 0 for other locations 
  20.      of the upper left hand corner of the window.  If the function returns 0, 
  21.      it can not restore the window, so it is up to the programmer to do it.
  22.  
  23.      I found these locations by snooping in compiled files.  They may not be
  24.      correct for other sub-versions of Turbo.  Almost surely, they will not be
  25.      correct for a new major revision.  As a result, the function is not
  26.      robust.
  27.  
  28.      It would be helpful if Borland were to give official ways to find the
  29.      window coordinates and to find the version.
  30.  
  31.      Lew Paper
  32.      12/9/85}
  33.  
  34.     VAR
  35.         x1_v2, y1_v2,           {Turbo Version 2 upper left hand coordinates}
  36.         x1_v287, y1_v287,       {Turbo-87 Version 2 upper left hand
  37.                                  coordinates}
  38.         x1_v3, y1_v3,           {Version 3 upper left hand coordinates}
  39.         x2, y2,                 {Lower right hand coordinates}
  40.         test_ulx, test_uly : INTEGER;
  41.  
  42.     BEGIN {FUNCTION which_turbo}
  43.  
  44.     {Save old values}
  45.  
  46.     x1_v2 := MEM[DSEG:$156] + 1;
  47.     y1_v2 := MEM[DSEG:$157] + 1;
  48.  
  49.     x1_v287 := MEM[DSEG:$143] + 1;
  50.     y1_v287 := MEM[DSEG:$144] + 1;
  51.  
  52.     x1_v3 := MEM[DSEG:$4] + 1;
  53.     y1_v3 := MEM[DSEG:$5] + 1;
  54.  
  55.     x2 := MEM[CSEG:$16A];
  56.     y2 := MEM[CSEG:$16B];
  57.  
  58.     {Bela Lubkin at Borland developed this method of finding a value of
  59.      test_ulx which equals neither x1_v2 nor x1_v3.}
  60.     test_ulx := 1;  {Arbitrary, so long as it is at least 3 less than maximum}
  61.     IF (x1_v2 = test_ulx) OR (x1_v287 = test_ulx) OR (x1_v3 = test_ulx)
  62.     THEN
  63.         BEGIN
  64.         test_ulx := 2;
  65.         IF (x1_v2 = test_ulx) OR (x1_v287 = test_ulx) OR (x1_v3 = test_ulx)
  66.         THEN
  67.             BEGIN
  68.             test_ulx := 3;
  69.             IF (x1_v2 = test_ulx) OR (x1_v287 = test_ulx)
  70.                 OR (x1_v3 = test_ulx) {All three are <= 3}
  71.             THEN
  72.                 test_ulx := 4;
  73.             END; {Middle IF (x1_v2 = test_ulx) OR (x1_v287 = test_ulx) OR
  74.                             (x1_v3 = test_ulx)}
  75.         END; {Outer IF (x1_v2 = test_ulx) OR (x1_v287 = test_ulx) OR
  76.               (x1_v3 = test_ulx)}
  77.     test_uly := 1;
  78.  
  79.     WINDOW(test_ulx, test_uly, x2, y2);
  80.  
  81.     IF MEM[DSEG:$4] = test_ulx - 1
  82.     THEN
  83.         which_turbo := 3
  84.     ELSE IF MEM[DSEG:$156] = test_ulx - 1
  85.     THEN
  86.         which_turbo := 2
  87.     ELSE IF MEM[DSEG:$143] = test_ulx - 1
  88.     THEN
  89.         which_turbo := 287
  90.     ELSE
  91.         which_turbo := 0;
  92.  
  93.     {Restore the original window}
  94.     IF MEM[DSEG:$4] = test_ulx - 1
  95.     THEN
  96.         WINDOW(x1_v3, y1_v3, x2, y2)
  97.     ELSE IF MEM[DSEG:$156] = test_ulx - 1
  98.     THEN
  99.         WINDOW(x1_v2, y1_v2, x2, y2)
  100.     ELSE IF MEM[DSEG:$143] = test_ulx - 1
  101.     THEN
  102.         WINDOW(x1_v287, y1_v287, x2, y2);
  103.  
  104.     END; {FUNCTION which_turbo}
  105.  
  106. (*
  107. VAR
  108.     version: INTEGER;
  109.  
  110. BEGIN {Test program}
  111.     CLRSCR;
  112.     WRITE('This is line 1 of the original window');
  113.     version := which_turbo;
  114.     IF version = 0
  115.     THEN
  116.         WINDOW(1, 1, 80, 25);
  117.     GOTOXY(1, 2);
  118.     WRITE('This is line 2 of the original window');
  119.     GOTOXY(1, 4);
  120.     IF version > 0
  121.     THEN
  122.         WRITE('The program was compiled by Turbo, Version ', version)
  123.     ELSE
  124.         WRITE('which_turbo cannot determine the version of Turbo which ',
  125.               'compiled this program');
  126. END. {Test program}
  127. *)
  128.